<template>
	<view class="container">
		<!-- 顶部导航栏 -->
		<view class="nav-bar">
			<view class="left">
				<u-icon name="arrow-left" size="32" color="#333" @click="goBack"></u-icon>
			</view>
			<view class="title">找回密码</view>
			<view class="right"></view>
		</view>
		
		<!-- 步骤指示器 -->
		<view class="steps">
			<view class="step" :class="{'active': currentStep >= 1}">
				<view class="dot">1</view>
				<text>验证手机</text>
			</view>
			<view class="line" :class="{'active': currentStep >= 2}"></view>
			<view class="step" :class="{'active': currentStep >= 2}">
				<view class="dot">2</view>
				<text>重置密码</text>
			</view>
		</view>
		
		<!-- 步骤一：验证手机 -->
		<view class="step-content" v-if="currentStep === 1">
			<view class="input-item">
				<u-icon name="phone" size="40" color="#666"></u-icon>
				<input type="number" v-model="form.phone" placeholder="请输入手机号" maxlength="11"/>
			</view>
			
			<view class="input-item code">
				<u-icon name="chat" size="40" color="#666"></u-icon>
				<input type="number" v-model="form.code" placeholder="请输入验证码" maxlength="6"/>
				<text class="send-code" 
					:class="{'disabled': counting}" 
					@click="sendCode">
					{{counting ? `${countdown}s后重试` : '获取验证码'}}
				</text>
			</view>
			
			<view class="next-btn" :class="{'disabled': !canNext}" @click="nextStep">
				<text>下一步</text>
			</view>
		</view>
		
		<!-- 步骤二：重置密码 -->
		<view class="step-content" v-if="currentStep === 2">
			<view class="input-item">
				<u-icon name="lock" size="40" color="#666"></u-icon>
				<input type="password" v-model="form.password" placeholder="请输入新密码"/>
			</view>
			
			<view class="input-item">
				<u-icon name="lock" size="40" color="#666"></u-icon>
				<input type="password" v-model="form.confirmPassword" placeholder="请确认新密码"/>
			</view>
			
			<view class="tips">
				<text>密码由6-20位字母、数字或符号组成</text>
			</view>
			
			<view class="submit-btn" :class="{'disabled': !canSubmit}" @click="handleSubmit">
				<text>确认修改</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				currentStep: 1,
				form: {
					phone: '',
					code: '',
					password: '',
					confirmPassword: ''
				},
				counting: false,
				countdown: 60
			}
		},
		computed: {
			canNext() {
				return this.form.phone && this.form.code
			},
			canSubmit() {
				return this.form.password && 
					this.form.confirmPassword && 
					this.form.password === this.form.confirmPassword
			}
		},
		methods: {
			goBack() {
				uni.navigateBack()
			},
			validatePhone() {
				const phoneReg = /^1[3-9]\d{9}$/
				if (!phoneReg.test(this.form.phone)) {
					uni.showToast({
						title: '请输入正确的手机号',
						icon: 'none'
					})
					return false
				}
				return true
			},
			sendCode() {
				if (this.counting) return
				
				if (!this.validatePhone()) return
				
				this.counting = true
				this.countdown = 60
				
				// 模拟发送验证码
				uni.showToast({
					title: '验证码已发送',
					icon: 'success'
				})
				
				const timer = setInterval(() => {
					if (this.countdown > 0) {
						this.countdown--
					} else {
						this.counting = false
						clearInterval(timer)
					}
				}, 1000)
			},
			nextStep() {
				if (!this.canNext) return
				
				if (!this.validatePhone()) return
				
				// 模拟验证码校验
				if (this.form.code !== '123456') {
					uni.showToast({
						title: '验证码错误',
						icon: 'none'
					})
					return
				}
				
				this.currentStep = 2
			},
			handleSubmit() {
				if (!this.canSubmit) return
				
				if (this.form.password.length < 6) {
					uni.showToast({
						title: '密码长度不能少于6位',
						icon: 'none'
					})
					return
				}
				
				uni.showLoading({
					title: '提交中...'
				})
				
				// 模拟提交
				setTimeout(() => {
					uni.hideLoading()
					uni.showToast({
						title: '密码修改成功',
						icon: 'success'
					})
					
					setTimeout(() => {
						uni.navigateBack()
					}, 1500)
				}, 1000)
			}
		}
	}
</script>

<style lang="scss">
	.container {
		min-height: 100vh;
		background-color: #fff;
		
		.nav-bar {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx 30rpx;
			background-color: #fff;
			
			.title {
				font-size: 36rpx;
				font-weight: bold;
				color: #333;
			}
		}
		
		.steps {
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 60rpx 0;
			
			.step {
				display: flex;
				flex-direction: column;
				align-items: center;
				
				.dot {
					width: 48rpx;
					height: 48rpx;
					border-radius: 24rpx;
					background-color: #F7F7FA;
					color: #999;
					font-size: 28rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					margin-bottom: 16rpx;
				}
				
				text {
					font-size: 28rpx;
					color: #999;
				}
				
				&.active {
					.dot {
						background-color: #1890FF;
						color: #fff;
					}
					
					text {
						color: #1890FF;
					}
				}
			}
			
			.line {
				width: 200rpx;
				height: 2rpx;
				background-color: #F7F7FA;
				margin: 0 40rpx;
				margin-bottom: 32rpx;
				
				&.active {
					background-color: #1890FF;
				}
			}
		}
		
		.step-content {
			padding: 0 40rpx;
			
			.input-item {
				display: flex;
				align-items: center;
				height: 100rpx;
				background-color: #F7F7FA;
				border-radius: 50rpx;
				padding: 0 40rpx;
				margin-bottom: 30rpx;
				
				input {
					flex: 1;
					height: 100%;
					font-size: 28rpx;
					color: #333;
					margin-left: 20rpx;
				}
				
				&.code {
					.send-code {
						font-size: 28rpx;
						color: #1890FF;
						padding-left: 30rpx;
						
						&.disabled {
							color: #999;
						}
					}
				}
			}
			
			.tips {
				padding: 20rpx 0;
				
				text {
					font-size: 24rpx;
					color: #999;
				}
			}
			
			.next-btn,
			.submit-btn {
				height: 88rpx;
				background-color: #1890FF;
				border-radius: 44rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				margin-top: 60rpx;
				
				text {
					font-size: 32rpx;
					color: #fff;
					font-weight: bold;
				}
				
				&.disabled {
					background-color: #ccc;
					opacity: 0.6;
				}
			}
		}
	}

	.login-link {
		text-align: center;
		margin-top: 40rpx;
		font-size: 28rpx;
		
		text {
			color: #3c9cff;
		}
	}

	.register-link {
		text-align: center;
		margin-top: 20rpx;
		font-size: 28rpx;
		
		text {
			color: #3c9cff;
		}
	}
</style> 